<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<link href="../css/estilos.css" rel="stylesheet" type="text/css" />
<%@ page import="java.util.*" %>
<%@ page import="beans.*" %>
<%@page  import="com.sun.org.apache.xerces.internal.impl.dv.util.Base64" %>

<jsp:useBean id="Materias" scope="request" class="databeans.MateriaDataBean" />
<jsp:useBean id="Alumnos" scope="request" class="databeans.AlumnoDataBean" />
<%
    String carnet = request.getParameter("carnet");
    AlumnoBean alumno = Alumnos.getAlumno(carnet);
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>EME:Detalle Alumno</title>
        <script language="javascript" type="text/javascript" src="../js/utilidades.js" ></script>
    </head>

    <body>
        <sec:authorize ifAnyGranted="ROLE_SYSTEM,ROLE_ALUMNO">
        <table  border="0" width="100%">
            <thead>
                <tr>
                    <th>
                        <h1><img src="../images/EME2.png" width="175px" alt="eme"></h1>
                    </th>
                    
                    <sec:authorize ifNotGranted="ROLE_ALUMNO">
                     <th>
                         <h1><img src="../images/headers/verAlumno.png" alt="ver alumno" ></h1>
                    </th>   
                    </sec:authorize>
                    <sec:authorize ifAllGranted="ROLE_ALUMNO">
                        <th>
                            <h1><img src="../images/headers/verPerfil.png" alt="ver perfil"></h1>
                        </th>
                    </sec:authorize>
                    

                </tr>
            </thead>
            <tbody>
                <tr>
                    <td width="200px" valign="top">
                         <div>
                            <jsp:include page="menu.jsp"/>
                        </div>
                    </td>
                    <td>
                        <div>
                        <h3>Datos Generales</h3>
                            <FORM name="form1" ACTION="../editAlumno" METHOD="POST" onsubmit="return validaForm(this)">
                               <table class="tabla2" border="0" style="margin: 0 auto; text-align: left;">
                                    <tbody>
                                       <tr>
                                           <td>
                                               Carnet:
                                           </td>
                                            <td>
                                                <input name="alumno"
                                                       size="10"
                                                       maxlength="7"
                                                       value="<%=alumno.getCarnet() %>"
                                                       disabled>
                                                <input type="hidden" name="carnet" value="<%= alumno.getCarnet()%>" />
                                           </td>
                                       </tr>
                                       <tr>
                                           <td>
                                               Nombre:
                                           </td>
                                           <td>
                                               <input name="nombre"
                                                      size="35"
                                                      maxlength="30"
                                                      value="<%= alumno.getNombre() %>">
                                           </td>
                                       </tr>
                                       <tr>
                                           <td>
                                               G&eacute;nero:
                                           </td>
                                           <td>
                                               <% if(alumno.getSexo()!= null) { %>

                                               <% if(alumno.getSexo().equals("M")){%>
                                               <INPUT TYPE="RADIO" NAME="sexo" VALUE="M" checked="true">Masculino
                                               <input type="radio" name="sexo" value="F">Femenino
                                               <%}else if(alumno.getSexo().equals("F")){ %>
                                               <INPUT TYPE="RADIO" NAME="sexo" VALUE="M">Masculino
                                               <input type="radio" name="sexo" value="F" checked="true">Femenino
                                                <%} %>
                                                <% } else { %>
                                                <INPUT TYPE="RADIO" NAME="sexo" VALUE="M">Masculino
                                                <input type="radio" name="sexo" value="F">Femenino

                                                <% } %>
                                           </td>
                                       </tr>
                                       <tr>
                                           <td>
                                               e-Mail:
                                           </td>
                                           <td>
                                              <input id="email"
                                                     name="email"
                                                     size="50"
                                                     maxlength="50"
                                                     value="<%= alumno.getEmail() %>" onchange="validarEmail(this)">
                                           </td>
                                       </tr>
                                       <sec:authorize ifAllGranted="ROLE_ALUMNO">
                                        <tr>
                                           <td>
                                               Tel&eacute;fono celular:
                                           </td>
                                           <td>
                                              <input name="telefono"
                                                     size="10"
                                                     maxlength="8"
                                                     <% if(alumno.getTelefono()!=null){ %>
                                                     value="<%= new String(Base64.decode(alumno.getTelefono())) %>"
                                                     <% } else { %>
                                                     value=""
                                                     <% } %>
                                                     onchange="validarCel(this)">
                                           </td>
                                       </tr>
                                       </sec:authorize>
                                       <tr>
                                           <td colspan="2"><button type="submit">Guardar cambios</button> </td>
                                       </tr>
                                   </tbody>
                               </table>
                            </FORM>
                            <br />
                        <h3>Materias</h3>
                            <table class="tabla1"  style="margin: 0 auto;">
                                <thead>
                                    <tr>
                                        <th width="150px">CodMateria</th>
                                        <th>Nombre de Materia</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <%
                                    List listaMat = Materias.getMateriasbyCarnet(carnet);
                                    Iterator it = listaMat.iterator();
                                    int i=0;
                                    while (it.hasNext()){
                                        MateriaBean materia = (MateriaBean)it.next();

                                    %>
                                    <tr>
                                    <td><%= materia.getCodMateria()%></td>
                                    <td><%= materia.getNomMateria()%></td>
                                    <sec:authorize ifAllGranted="ROLE_SYSTEM">
                                    <td><a href="../quitarMateria?codmateria=<%= materia.getCodMateria()%>&carnet=<%=alumno.getCarnet()%>">Quitar Materia</a></td>
                                    </sec:authorize>
                                    </tr>
                                    <%
                                    }
                                    %>
                                </tbody>
                            </table>
                            <br />
                            <sec:authorize ifAllGranted="ROLE_SYSTEM">
                                <hr width="70%">
                                <form name="form2" ACTION="../addMateriasAlumno" METHOD="POST">
                                    <input type="hidden" name="carnet" value="<%=alumno.getCarnet()%>">
                                    <table style="margin: 0 auto;">
                                        <thead>
                                            <tr>
                                                <th>
                                                    <h3>Agregar Materia</h3>
                                                </th>
                                            </tr>
                                        </thead>
                                        <tbody style="text-align: left;">
                                            <tr>
                                                <td>
                                                    <%
                                                    List listaMatNuevas = Materias.getMateriasDistintasbyCarnet(carnet);
                                                    Iterator ite = listaMatNuevas.iterator();
                                                    while (ite.hasNext()){
                                                        MateriaBean materia = (MateriaBean)ite.next();

                                                    %>
                                                    <input name="materias" type="checkbox" value="<%= materia.getCodMateria()%>">
                                                        <%= materia.getNomMateria()%>
                                                   <br>
                                                    <%
                                                    }
                                                    %>

                                               </td>
                                           </tr>
                                           <tr>
                                               <td align="center">
                                                   <input type="submit" value="Aceptar">
                                               </td>
                                           </tr>
                                        </tbody>
                                    </table>
                                </form>
                            </sec:authorize>
                    </div>
                    </td>
                </tr>
            </tbody>
        </table>
        <br />
        <div align="left">
            <jsp:include page="barrausuario.jsp"/>
        </div>
        </sec:authorize>
    </body>
    
</html>
